home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / TranslationPanel.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  20KB  |  808 lines

  1. /*
  2. **    TranslationPanel.c
  3. **
  4. **    Character code translation editing panel
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* The character table. */
  13.  
  14. STATIC STRPTR CharCodes[256] =
  15. {
  16.     "NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS" ,"HT" ,"LF" ,"VT" ,"FF" ,"CR" ,"SO" ,"SI" ,
  17.     "DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM" ,"SUB","ESC","FS" ,"GS" ,"RS" ,"US" ,
  18.     "SP" , "!" , "\"", "#" , "$" , "%" , "&" , "'" , "(" , ")" , "*" , "+" , "," , "-" , "." , "/" ,
  19.      "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , ":" , ";" , "<" , "=" , ">" , "?" ,
  20.      "@" , "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" ,
  21.      "P" , "Q" , "R" , "S" , "T" , "U" , "V" , "W" , "X" , "Y" , "Z" , "[" , "\\", "]" , "^" , "_" ,
  22.      "`" , "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" ,
  23.      "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z" , "{" , "|" , "}" , "~" ,"DEL",
  24.     "128","129","130","131","132","133","134","135","136","137","138","139","140","141","SS2","SS3",
  25.     "DCS","145","146","147","148","149","150","151","152","153","154","CSI","ST" ,"OSC","PM" ,"APC",
  26.     "NBS", "¡" , "¢" , "£" , "¤" , "¥" , "¦" , "§" , "¨" , "©" , "ª" , "«" , "¬" ,"SHY", "®" , "¯" ,
  27.      "°" , "±" , "²" , "³" , "´" , "µ" , "¶" , "·" , "¸" , "¹" , "º" , "»" , "¼" , "½" , "¾" , "¿" ,
  28.      "À" , "Á" , "Â" , "Ã" , "Ä" , "Å" , "Æ" , "Ç" , "È" , "É" , "Ê" , "Ë" , "Ì" , "Í" , "Î" , "Ï" ,
  29.      "Ð" , "Ñ" , "Ò" , "Ó" , "Ô" , "Õ" , "Ö" , "×" , "Ø" , "Ù" , "Ú" , "Û" , "Ü" , "Ý" , "Þ" , "ß" ,
  30.      "à" , "á" , "â" , "ã" , "ä" , "å" , "æ" , "ç" , "è" , "é" , "ê" , "ë" , "ì" , "í" , "î" , "ï" ,
  31.      "ð" , "ñ" , "ò" , "ó" , "ô" , "õ" , "ö" , "÷" , "ø" , "ù" , "ú" , "û" , "ü" , "ý" , "þ" , "ÿ"
  32. };
  33.  
  34.     /* Main control panel gadget IDs. */
  35.  
  36. enum    {    MAINGAD_HALF=256,MAINGAD_USE,MAINGAD_LOAD,MAINGAD_SAVE,MAINGAD_CANCEL };
  37.  
  38.     /* The local settings panel gadget IDs. */
  39.  
  40. enum    {    SUBGAD_CODE,SUBGAD_SEND,SUBGAD_RECEIVE,SUBGAD_USE,SUBGAD_CANCEL };
  41.  
  42. STATIC STRPTR Halfs[] =
  43. {
  44.     "NUL-DEL",
  45.     "128-\"ÿ\"",
  46.     NULL
  47. };
  48.  
  49. STATIC struct Gadget *
  50. CreateAllMainGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,BYTE *Half)
  51. {
  52.     struct Gadget        *Gadget;
  53.     struct NewGadget     NewGadget;
  54.     UWORD             Counter;
  55.  
  56.     FOREVER
  57.     {
  58.         SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  59.  
  60.         memset(&NewGadget,0,sizeof(struct NewGadget));
  61.  
  62.         if(Gadget = CreateContext(GadgetList))
  63.         {
  64.             WORD i,From,To;
  65.  
  66.             switch(*Half)
  67.             {
  68.                 case 0:
  69.  
  70.                     From    = 0;
  71.                     To    = 127;
  72.  
  73.                     break;
  74.  
  75.                 case 1:
  76.  
  77.                     From    = 128;
  78.                     To    = 255;
  79.  
  80.                     break;
  81.  
  82.                 case 2:
  83.  
  84.                     From    = 0;
  85.                     To    = 255;
  86.  
  87.                     break;
  88.             }
  89.  
  90.             SZ_ResetMaxWidth();
  91.  
  92.             for(i = From ; i <= To ; i++)
  93.                 SZ_UpdateMaxWidth(BUTTON_KIND,CharCodes[i],0,NULL);
  94.  
  95.             SZ_SetWidth(SZ_ResetMaxWidth());
  96.  
  97.             for(i = From ; i <= To ; i++)
  98.             {
  99.                 if(i == (To + 1) / 2 - 1)
  100.                 {
  101.                     if(SZ_GetWindowHeight() > Window -> WScreen -> Height / 2)
  102.                     {
  103.                         if(*Half == 2)
  104.                         {
  105.                             *Half = 0;
  106.  
  107.                             To = 127;
  108.                         }
  109.                     }
  110.                 }
  111.  
  112.                 NewGadget . ng_GadgetText    = CharCodes[i];
  113.                 NewGadget . ng_GadgetID        = i;
  114.  
  115.                 if(!(i % 16))
  116.                 {
  117.                     GadgetArray[i] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  118.                         SZ_Adjust,    TRUE,
  119.                         SZ_AutoWidth,    TRUE,
  120.  
  121.                         SZ_GroupCount,    16,
  122.                         SZ_AlignBottom,    TRUE,
  123.                     TAG_DONE);
  124.                 }
  125.                 else
  126.                 {
  127.                     GadgetArray[i] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  128.                         SZ_Adjust,    TRUE,
  129.                         SZ_AutoWidth,    TRUE,
  130.  
  131.                         SZ_GroupNext,    TRUE,
  132.                     TAG_DONE);
  133.                 }
  134.             }
  135.  
  136.             if(*Half < 2)
  137.             {
  138.                 Counter = MAINGAD_HALF;
  139.  
  140.                 NewGadget . ng_GadgetText    = LocaleString(MSG_TRANSLATIONPANEL_CHARACTER_PAGE_GAD);
  141.                 NewGadget . ng_GadgetID        = Counter;
  142.  
  143.                 GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  144.                     SZ_Adjust,    TRUE,
  145.                     SZ_AlignExtra,    TRUE,
  146.                     SZ_AlignCentre,    TRUE,
  147.                     SZ_AlignBottom,    TRUE,
  148.  
  149.                     GTCY_Labels,    Halfs,
  150.                     GTCY_Active,    *Half,
  151.                 TAG_DONE);
  152.             }
  153.             else
  154.                 Counter = MAINGAD_USE;
  155.  
  156.             SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  157.             SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  158.             SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_LOAD_GAD),0,NULL);
  159.             SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  160.  
  161.             SZ_SetWidth(SZ_ResetMaxWidth());
  162.  
  163.             NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_USE_GAD);
  164.             NewGadget . ng_GadgetID        = Counter;
  165.             NewGadget . ng_Flags        = 0;
  166.  
  167.             GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  168.                 SZ_Adjust,    TRUE,
  169.                 SZ_AutoWidth,    TRUE,
  170.                 SZ_AlignExtra,    TRUE,
  171.                 SZ_AlignLeft,    TRUE,
  172.                 SZ_AlignBottom,    TRUE,
  173.                 SZ_GroupCount,    4,
  174.             TAG_DONE);
  175.  
  176.             NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_LOAD_GAD);
  177.             NewGadget . ng_GadgetID        = Counter;
  178.  
  179.             GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  180.                 SZ_Adjust,    TRUE,
  181.                 SZ_AutoWidth,    TRUE,
  182.                 SZ_GroupNext,    TRUE,
  183.             TAG_DONE);
  184.  
  185.             NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_SAVE_GAD);
  186.             NewGadget . ng_GadgetID        = Counter;
  187.  
  188.             GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  189.                 SZ_Adjust,    TRUE,
  190.                 SZ_AutoWidth,    TRUE,
  191.                 SZ_GroupNext,    TRUE,
  192.             TAG_DONE);
  193.  
  194.             NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_CANCEL_GAD);
  195.             NewGadget . ng_GadgetID        = Counter;
  196.  
  197.             GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  198.                 SZ_Adjust,    TRUE,
  199.                 SZ_AutoWidth,    TRUE,
  200.                 SZ_GroupNext,    TRUE,
  201.             TAG_DONE);
  202.  
  203.             if(SZ_GetWindowHeight() > Window -> WScreen -> Height)
  204.             {
  205.                 FreeGadgets(*GadgetList);
  206.  
  207.                 *GadgetList = NULL;
  208.  
  209.                 if(*Half == 2)
  210.                     *Half = 0;
  211.                 else
  212.                     return(NULL);
  213.             }
  214.             else
  215.                 return(Gadget);
  216.         }
  217.         else
  218.             return(NULL);
  219.     }
  220. }
  221.  
  222. STATIC struct Gadget *
  223. CreateAllSubGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,STRPTR Buffer)
  224. {
  225.     struct Gadget        *Gadget;
  226.     struct NewGadget     NewGadget;
  227.     UWORD             Counter = 0;
  228.  
  229.     SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  230.  
  231.     memset(&NewGadget,0,sizeof(struct NewGadget));
  232.  
  233.     if(Gadget = CreateContext(GadgetList))
  234.     {
  235.         SZ_ResetMaxWidth();
  236.  
  237.         SZ_UpdateMaxWidth(TEXT_KIND,NULL,strlen(Buffer),NULL);
  238.         SZ_UpdateMaxWidth(STRING_KIND,NULL,40,NULL);
  239.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  240.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  241.  
  242.         SZ_SetWidth(SZ_ResetMaxWidth());
  243.  
  244.         SZ_InitWidth();
  245.  
  246.         NewGadget . ng_GadgetText    = LocaleString(MSG_TRANSLATIONPANEL_CHARACTER_CODE_GAD);
  247.         NewGadget . ng_GadgetID        = Counter;
  248.         NewGadget . ng_Flags        = PLACETEXT_ABOVE;
  249.  
  250.         GadgetArray[Counter++] = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  251.             SZ_Adjust,        TRUE,
  252.             SZ_AlignCentre,        TRUE,
  253.             SZ_Chars,        strlen(Buffer),
  254.  
  255.             GTTX_Text,        Buffer,
  256.             GTTX_Border,        TRUE,
  257.             GTTX_Justification,    GTJ_CENTER,
  258.         TAG_DONE);
  259.  
  260.         NewGadget . ng_GadgetText    = LocaleString(MSG_TRANSLATIONPANEL_SEND_CODE_AS_GAD);
  261.         NewGadget . ng_GadgetID        = Counter;
  262.  
  263.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  264.             SZ_Adjust,        TRUE,
  265.             SZ_AlignExtra,        TRUE,
  266.             SZ_AlignBottom,        TRUE,
  267.             SZ_AlignLeft,        TRUE,
  268.             SZ_Chars,        40,
  269.             STRINGA_Justification,    GACT_STRINGCENTER,
  270.  
  271.             GTST_MaxChars,        255,
  272.             GA_Immediate,        TRUE,
  273.         TAG_DONE);
  274.  
  275.         NewGadget . ng_GadgetText    = LocaleString(MSG_TRANSLATIONPANEL_RECEIVE_CODE_AS_GAD);
  276.         NewGadget . ng_GadgetID        = Counter;
  277.  
  278.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  279.             SZ_Adjust,        TRUE,
  280.             SZ_AlignExtra,        TRUE,
  281.             SZ_AlignBottom,        TRUE,
  282.             SZ_AlignLeft,        TRUE,
  283.             SZ_Chars,        40,
  284.             STRINGA_Justification,    GACT_STRINGCENTER,
  285.  
  286.             GTST_MaxChars,        255,
  287.             GA_Immediate,        TRUE,
  288.         TAG_DONE);
  289.  
  290.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  291.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  292.  
  293.         SZ_SetWidth(SZ_ResetMaxWidth());
  294.  
  295.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_USE_GAD);
  296.         NewGadget . ng_GadgetID        = Counter;
  297.         NewGadget . ng_Flags        = 0;
  298.  
  299.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  300.             SZ_Adjust,    TRUE,
  301.             SZ_AutoWidth,    TRUE,
  302.             SZ_AlignExtra,    TRUE,
  303.             SZ_AlignLeft,    TRUE,
  304.             SZ_AlignBottom,    TRUE,
  305.         TAG_DONE);
  306.  
  307.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_CANCEL_GAD);
  308.         NewGadget . ng_GadgetID        = Counter;
  309.  
  310.         GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  311.             SZ_Adjust,    TRUE,
  312.             SZ_AutoWidth,    TRUE,
  313.             SZ_AlignRight,    TRUE,
  314.         TAG_DONE);
  315.     }
  316.  
  317.     return(Gadget);
  318. }
  319.  
  320. STATIC BYTE
  321. SubPanel(UBYTE CharCode)
  322. {
  323.     struct Window    *PanelWindow;
  324.     struct Gadget    *GadgetList = NULL;
  325.     struct Gadget    *GadgetArray[SUBGAD_CANCEL + 1];
  326.     BYTE         Result = FALSE;
  327.  
  328.     if(CharCodes[CharCode][0] == '1' && CharCodes[CharCode][1])
  329.         strcpy(SharedBuffer,CharCodes[CharCode]);
  330.     else
  331.         SPrintf(SharedBuffer,"%ld (\"%s\")",CharCode,CharCodes[CharCode]);
  332.  
  333.     if(CreateAllSubGadgets(GadgetArray,&GadgetList,SharedBuffer))
  334.     {
  335.         if(PanelWindow = OpenWindowTags(NULL,
  336.             WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  337.             WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  338.             WA_Width,    SZ_GetWindowWidth(),
  339.             WA_Height,    SZ_GetWindowHeight(),
  340.  
  341.             WA_Activate,    TRUE,
  342.             WA_DragBar,    TRUE,
  343.             WA_DepthGadget,    TRUE,
  344.             WA_RMBTrap,    TRUE,
  345.             WA_DepthGadget,    TRUE,
  346.             WA_CloseGadget,    TRUE,
  347.             WA_CustomScreen,Window -> WScreen,
  348.  
  349.             WA_IDCMP,    IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY | IDCMP_VANILLAKEY | BUTTONIDCMP | STRINGIDCMP,
  350.  
  351.             WA_Title,    LocaleString(MSG_TRANSLATIONPANEL_CHARACTER_CODE_TRANSLATION_TXT),
  352.         TAG_DONE))
  353.         {
  354.             struct IntuiMessage    *Massage;
  355.             ULONG             IClass,Code;
  356.             struct Gadget        *Gadget;
  357.             BYTE             Terminated = FALSE;
  358.             STRPTR             SendText    = NULL,
  359.                          ReceiveText    = NULL;
  360.  
  361.             GuideContext(CONTEXT_TRANSLATION);
  362.  
  363.             PushWindow(PanelWindow);
  364.  
  365.             AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  366.             RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  367.             GT_RefreshWindow(PanelWindow,NULL);
  368.  
  369.             ActiveGadget = NULL;
  370.  
  371.             if(SendTable[CharCode])
  372.             {
  373.                 TranslateBack(SendTable[CharCode] -> String,SendTable[CharCode] -> Len,SharedBuffer);
  374.  
  375.                 GT_SetGadgetAttrs(GadgetArray[SUBGAD_SEND],PanelWindow,NULL,
  376.                     GTST_String,SharedBuffer,
  377.                 TAG_DONE);
  378.             }
  379.  
  380.             if(ReceiveTable[CharCode])
  381.             {
  382.                 TranslateBack(ReceiveTable[CharCode] -> String,ReceiveTable[CharCode] -> Len,SharedBuffer);
  383.  
  384.                 GT_SetGadgetAttrs(GadgetArray[SUBGAD_RECEIVE],PanelWindow,NULL,
  385.                     GTST_String,SharedBuffer,
  386.                 TAG_DONE);
  387.             }
  388.  
  389.             SetSignal(0,SIG_BREAK);
  390.  
  391.             while(!Terminated)
  392.             {
  393.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  394.                     break;
  395.  
  396.                 while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  397.                 {
  398.                     IClass    = Massage -> Class;
  399.                     Code    = Massage -> Code;
  400.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  401.  
  402.                     GT_ReplyIMsg(Massage);
  403.  
  404.                     KeySelect(GadgetArray,SUBGAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
  405.  
  406.                     if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
  407.                         ActivateGadget(ActiveGadget,PanelWindow,NULL);
  408.  
  409.                     if(IClass == IDCMP_GADGETDOWN)
  410.                     {
  411.                         if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  412.                             ActiveGadget = Gadget;
  413.                     }
  414.  
  415.                     if(IClass == IDCMP_CLOSEWINDOW)
  416.                         Terminated = TRUE;
  417.  
  418.                     if(IClass == IDCMP_GADGETUP)
  419.                     {
  420.                         switch(Gadget -> GadgetID)
  421.                         {
  422.                             case SUBGAD_SEND:
  423.  
  424.                                 ActivateGadget(ActiveGadget = GadgetArray[SUBGAD_RECEIVE],PanelWindow,NULL);
  425.                                 break;
  426.  
  427.                             case SUBGAD_USE:
  428.  
  429.                                 SendText    = SZ_GetString(GadgetArray[SUBGAD_SEND]);
  430.                                 ReceiveText    = SZ_GetString(GadgetArray[SUBGAD_RECEIVE]);
  431.  
  432.                                 Terminated = TRUE;
  433.                                 break;
  434.  
  435.                             case SUBGAD_CANCEL:
  436.  
  437.                                 Terminated = TRUE;
  438.                                 break;
  439.                         }
  440.                     }
  441.                 }
  442.             }
  443.  
  444.             if(GadgetList)
  445.                 RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  446.  
  447.             if(SendText)
  448.             {
  449.                 if(*SendText)
  450.                 {
  451.                     struct TranslationEntry *Entry = AllocTranslationEntry(SendText);
  452.  
  453.                     if(Entry)
  454.                     {
  455.                         if(SendTable[CharCode])
  456.                             FreeTranslationEntry(SendTable[CharCode]);
  457.  
  458.                         SendTable[CharCode] = Entry;
  459.  
  460.                         Result = TRUE;
  461.                     }
  462.                 }
  463.                 else
  464.                 {
  465.                     if(SendTable[CharCode])
  466.                         FreeTranslationEntry(SendTable[CharCode]);
  467.  
  468.                     SendTable[CharCode] = NULL;
  469.  
  470.                     Result = TRUE;
  471.                 }
  472.             }
  473.  
  474.             if(ReceiveText)
  475.             {
  476.                 if(*ReceiveText)
  477.                 {
  478.                     struct TranslationEntry *Entry = AllocTranslationEntry(ReceiveText);
  479.  
  480.                     if(Entry)
  481.                     {
  482.                         if(ReceiveTable[CharCode])
  483.                             FreeTranslationEntry(ReceiveTable[CharCode]);
  484.  
  485.                         ReceiveTable[CharCode] = Entry;
  486.  
  487.                         Result = TRUE;
  488.                     }
  489.                 }
  490.                 else
  491.                 {
  492.                     if(ReceiveTable[CharCode])
  493.                         FreeTranslationEntry(ReceiveTable[CharCode]);
  494.  
  495.                     ReceiveTable[CharCode] = NULL;
  496.  
  497.                     Result = TRUE;
  498.                 }
  499.             }
  500.  
  501.             PopWindow();
  502.  
  503.             CloseWindow(PanelWindow);
  504.         }
  505.     }
  506.  
  507.     FreeGadgets(GadgetList);
  508.  
  509.     return(Result);
  510. }
  511.  
  512. BYTE
  513. TranslationPanel()
  514. {
  515.     struct Window    *PanelWindow;
  516.     struct Gadget    *GadgetList = NULL;
  517.     struct Gadget    **GadgetArray;
  518.     BYTE         Half        = 2;
  519.     BYTE         MadeChanges    = FALSE,
  520.              Created    = FALSE;
  521.  
  522.     if(!SendTable)
  523.     {
  524.         if(!(SendTable = AllocTranslationTable()))
  525.         {
  526.             DisplayBeep(Window -> WScreen);
  527.  
  528.             return(FALSE);
  529.         }
  530.  
  531.         if(!(ReceiveTable = AllocTranslationTable()))
  532.         {
  533.             DisplayBeep(Window -> WScreen);
  534.  
  535.             FreeTranslationTable(SendTable);
  536.  
  537.             SendTable = NULL;
  538.  
  539.             return(FALSE);
  540.         }
  541.  
  542.         if(!FillTranslationTable(SendTable))
  543.         {
  544.             DisplayBeep(Window -> WScreen);
  545.  
  546.             FreeTranslationTable(SendTable);
  547.  
  548.             SendTable = NULL;
  549.  
  550.             FreeTranslationTable(ReceiveTable);
  551.  
  552.             ReceiveTable = NULL;
  553.  
  554.             return(FALSE);
  555.         }
  556.  
  557.         if(!FillTranslationTable(ReceiveTable))
  558.         {
  559.             DisplayBeep(Window -> WScreen);
  560.  
  561.             FreeTranslationTable(SendTable);
  562.  
  563.             SendTable = NULL;
  564.  
  565.             FreeTranslationTable(ReceiveTable);
  566.  
  567.             ReceiveTable = NULL;
  568.  
  569.             return(FALSE);
  570.         }
  571.  
  572.         Created = TRUE;
  573.     }
  574.  
  575.     if(GadgetArray = (struct Gadget **)AllocVec(sizeof(struct Gadget *) * (MAINGAD_CANCEL + 1),MEMF_ANY | MEMF_CLEAR))
  576.     {
  577.         if(CreateAllMainGadgets(GadgetArray,&GadgetList,&Half))
  578.         {
  579.             if(PanelWindow = OpenWindowTags(NULL,
  580.                 WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  581.                 WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  582.                 WA_Width,    SZ_GetWindowWidth(),
  583.                 WA_Height,    SZ_GetWindowHeight(),
  584.  
  585.                 WA_Activate,    TRUE,
  586.                 WA_DragBar,    TRUE,
  587.                 WA_DepthGadget,    TRUE,
  588.                 WA_RMBTrap,    TRUE,
  589.                 WA_DepthGadget,    TRUE,
  590.                 WA_CloseGadget,    TRUE,
  591.                 WA_CustomScreen,Window -> WScreen,
  592.  
  593.                 WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | BUTTONIDCMP | CYCLEIDCMP,
  594.  
  595.                 WA_Title,    LocaleString(MSG_TRANSLATIONPANEL_CHARACTER_TABLE_TXT),
  596.             TAG_DONE))
  597.             {
  598.                 struct IntuiMessage    *Massage;
  599.                 ULONG             IClass,Code;
  600.                 struct Gadget        *Gadget;
  601.                 BYTE             Terminated = FALSE;
  602.  
  603.                 UBYTE             DummyBuffer[256],
  604.                             *DummyChar;
  605.  
  606.                 struct FileRequester    *FileRequest;
  607.  
  608.                 PushWindow(PanelWindow);
  609.  
  610.                 AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  611.                 RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  612.                 GT_RefreshWindow(PanelWindow,NULL);
  613.  
  614.                 ActiveGadget = NULL;
  615.  
  616.                 SetSignal(0,SIG_BREAK);
  617.  
  618.                 while(!Terminated)
  619.                 {
  620.                     if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  621.                         break;
  622.  
  623.                     while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  624.                     {
  625.                         IClass    = Massage -> Class;
  626.                         Code    = Massage -> Code;
  627.                         Gadget    = (struct Gadget *)Massage -> IAddress;
  628.  
  629.                         GT_ReplyIMsg(Massage);
  630.  
  631.                         if(IClass == IDCMP_VANILLAKEY)
  632.                             KeySelect(GadgetArray,MAINGAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
  633.  
  634.                         if(IClass == IDCMP_CLOSEWINDOW)
  635.                             Terminated = TRUE;
  636.  
  637.                         if(IClass == IDCMP_GADGETUP)
  638.                         {
  639.                             switch(Gadget -> GadgetID)
  640.                             {
  641.                                 case MAINGAD_HALF:
  642.  
  643.                                     BlockWindow(PanelWindow);
  644.  
  645.                                     Half = Code;
  646.  
  647.                                     RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  648.  
  649.                                     FreeGadgets(GadgetList);
  650.  
  651.                                     GadgetList = NULL;
  652.  
  653.                                     memset(GadgetArray,0,sizeof(struct Gadget *) * (MAINGAD_CANCEL + 1));
  654.  
  655.                                     if(CreateAllMainGadgets(GadgetArray,&GadgetList,&Half))
  656.                                     {
  657.                                         AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  658.                                         RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  659.                                         GT_RefreshWindow(PanelWindow,NULL);
  660.  
  661.                                         ActiveGadget = NULL;
  662.                                     }
  663.  
  664.                                     ReleaseWindow(PanelWindow);
  665.  
  666.                                     break;
  667.  
  668.                                 case MAINGAD_LOAD:
  669.  
  670.                                     strcpy(DummyBuffer,LastTranslation);
  671.  
  672.                                     DummyChar = PathPart(DummyBuffer);
  673.  
  674.                                     *DummyChar = 0;
  675.  
  676.                                     BlockWindow(PanelWindow);
  677.  
  678.                                     if(FileRequest = GetFile(LocaleString(MSG_TRANSLATIONPANEL_LOAD_TRANSLATION_TABLES_TXT),DummyBuffer,FilePart(LastTranslation),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
  679.                                     {
  680.                                         struct TranslationEntry **Send,**Receive = NULL;
  681.                                         BYTE Success = FALSE;
  682.  
  683.                                         if(Send = AllocTranslationTable())
  684.                                         {
  685.                                             if(Receive = AllocTranslationTable())
  686.                                                 Success = LoadTranslationTables(DummyBuffer,Send,Receive);
  687.                                         }
  688.  
  689.                                         if(!Success)
  690.                                         {
  691.                                             MyEasyRequest(Window,LocaleString(MSG_TRANSLATIONPANEL_COULD_NOT_LOAD_TRANSLATION_TABLES_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  692.  
  693.                                             if(Send)
  694.                                                 FreeTranslationTable(Send);
  695.  
  696.                                             if(Receive)
  697.                                                 FreeTranslationTable(Receive);
  698.                                         }
  699.                                         else
  700.                                         {
  701.                                             strcpy(Config -> FileConfig -> TranslationFileName,DummyBuffer);
  702.  
  703.                                             strcpy(LastTranslation,DummyBuffer);
  704.  
  705.                                             MadeChanges    = FALSE;
  706.                                             Created        = FALSE;
  707.  
  708.                                             FreeTranslationTable(SendTable);
  709.                                             FreeTranslationTable(ReceiveTable);
  710.  
  711.                                             SendTable    = Send;
  712.                                             ReceiveTable    = Receive;
  713.                                         }
  714.  
  715.                                         FreeAslRequest(FileRequest);
  716.                                     }
  717.  
  718.                                     ReleaseWindow(PanelWindow);
  719.  
  720.                                     break;
  721.  
  722.                                 case MAINGAD_SAVE:
  723.  
  724.                                     strcpy(DummyBuffer,LastTranslation);
  725.  
  726.                                     DummyChar = PathPart(DummyBuffer);
  727.  
  728.                                     *DummyChar = 0;
  729.  
  730.                                     BlockWindow(PanelWindow);
  731.  
  732.                                     if(FileRequest = GetFile(LocaleString(MSG_TRANSLATIONPANEL_SAVE_TRANSLATION_TABLES_TXT),DummyBuffer,FilePart(LastTranslation),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
  733.                                     {
  734.                                         if(!SaveTranslationTables(DummyBuffer,SendTable,ReceiveTable))
  735.                                             MyEasyRequest(Window,LocaleString(MSG_TRANSLATIONPANEL_COULD_NOT_SAVE_TRANSLATION_TABLES_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),DummyBuffer);
  736.                                         else
  737.                                         {
  738.                                             strcpy(LastTranslation,DummyBuffer);
  739.  
  740.                                             MadeChanges = FALSE;
  741.  
  742.                                             Created = FALSE;
  743.                                         }
  744.  
  745.                                         FreeAslRequest(FileRequest);
  746.                                     }
  747.  
  748.                                     ReleaseWindow(PanelWindow);
  749.  
  750.                                     break;
  751.  
  752.                                 case MAINGAD_USE:
  753.  
  754.                                     strcpy(Config -> FileConfig -> TranslationFileName,LastTranslation);
  755.  
  756.                                     Terminated = TRUE;
  757.                                     break;
  758.  
  759.                                 case MAINGAD_CANCEL:
  760.  
  761.                                     Terminated = TRUE;
  762.                                     break;
  763.  
  764.                                 default:
  765.  
  766.                                     if(Gadget -> GadgetID < 256)
  767.                                     {
  768.                                         BlockWindow(PanelWindow);
  769.  
  770.                                         MadeChanges |= SubPanel(Gadget -> GadgetID);
  771.  
  772.                                         ReleaseWindow(PanelWindow);
  773.                                     }
  774.  
  775.                                     break;
  776.                             }
  777.                         }
  778.                     }
  779.                 }
  780.  
  781.                 if(GadgetList)
  782.                     RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  783.  
  784.                 PopWindow();
  785.  
  786.                 CloseWindow(PanelWindow);
  787.             }
  788.         }
  789.  
  790.         FreeGadgets(GadgetList);
  791.  
  792.         FreeVec(GadgetArray);
  793.     }
  794.  
  795.     if(!MadeChanges && Created || (IsStandardTable(SendTable) && IsStandardTable(ReceiveTable)))
  796.     {
  797.         FreeTranslationTable(SendTable);
  798.  
  799.         SendTable = NULL;
  800.  
  801.         FreeTranslationTable(ReceiveTable);
  802.  
  803.         ReceiveTable = NULL;
  804.     }
  805.  
  806.     return(MadeChanges);
  807. }
  808.